package erfgame.core.world.terrain.update;


import erfgame.core.Rectangle3D;
import erfgame.core.memory.Pointer;

public class TerrainBlockUpdateResult {
	private byte[][][][][][] sample;
	private int[][][][][] surfaces;
	private Rectangle3D sampleBounds;
	private Rectangle3D coverage;
	private Pointer<byte[][][]>[][][] pointers;
	private int lowestUnderTerrainZ;
	private int highestUnderTerrainZ;
	private byte[][][][][][] shadowSample;
	private Pointer<byte[][][]>[][][] shadowPointers;
	private int minSampleZ;
	private int maxSampleZ;
	
	public TerrainBlockUpdateResult( Rectangle3D sampleBounds, Rectangle3D coverage, byte[][][][][][] sample, int[][][][][] surfaces, Pointer<byte[][][]>[][][] pointers ) {
		this.sampleBounds = sampleBounds;
		this.coverage = coverage;
		this.sample = sample;
		this.pointers = pointers;
		this.surfaces = surfaces;
	}
	
	public byte[][][][][][] getSample() {
		return this.sample;
	}
	
	public int[][][][][] getSurfaces() {
		return this.surfaces;
	}
	
	public Rectangle3D getSampleBounds() {
		return this.sampleBounds;
	}
	
	public Rectangle3D getCoverage() {
		return this.coverage;
	}
	
	public void free() {
		free( pointers );
		if( shadowPointers != null ) {
			free(shadowPointers);
			shadowPointers = null;
		}
		pointers = null;
	}
	
	private void free( Pointer<byte[][][]>[][][] pointers ) {
		for( int x=pointers.length; x>0; ){
			x--;
			for( int y=pointers[x].length; y>0; ){
				y--;
				for( int z=pointers[x][y].length; z>0; ){
					z--;
					pointers[x][y][z].free();
				}
			}
		}
	}

	public int getLowestUnderTerrainZ() {
		return lowestUnderTerrainZ;
	}
	
	public int getHighestUnderTerrainZ() {
		return this.highestUnderTerrainZ;
	}

	public void setUnderTerrainZ(int highestUnderTerrainZ, int lowestUnderTerrainZ) {
		this.lowestUnderTerrainZ = lowestUnderTerrainZ;
		this.highestUnderTerrainZ = highestUnderTerrainZ;
	}
	
	public int getMinShadowSampleZ() {
		return this.minSampleZ;
	}
	
	public int getMaxShadowSampleZ() {
		return this.maxSampleZ;
	}

	public byte[][][][][][] getShadowSample() {
		return shadowSample;
	}

	public void setShadowSample(byte[][][][][][] shadowSample, int minSampleZ, int maxSampleZ ) {
		this.shadowSample = shadowSample;
		this.minSampleZ = minSampleZ;
		this.maxSampleZ = maxSampleZ;
	}

	public Pointer<byte[][][]>[][][] getShadowPointers() {
		return shadowPointers;
	}

	public void setShadowPointers(Pointer<byte[][][]>[][][] shadowPointers) {
		this.shadowPointers = shadowPointers;
	}
}
